﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win.UltraWinGrid;
using WHC.OrderWater.Commons;
using Infragistics.Win.UltraWinToolTip;
using Infragistics.Win;
using System.Collections;

namespace CKNetFrameWork
{
    public partial class Frm_ClassPrdSchd : DockContent
    {
        private Dictionary<string, string> m_dicHelper = new Dictionary<string, string>();
        private UltraToolTipManager toolTipManager = new UltraToolTipManager();
        private TrainingDB.BLL.CK_ClassPrdSchdTab m_bllCK_ClassPrdSchdTab = new TrainingDB.BLL.CK_ClassPrdSchdTab();
        private TrainingDB.BLL.CK_SchoolTab m_bllCK_SchoolTab = new TrainingDB.BLL.CK_SchoolTab();
        private TrainingDB.BLL.CK_TeacherTab m_bllCK_TeacherTab = new TrainingDB.BLL.CK_TeacherTab();
        private TrainingDB.BLL.CK_CourseTab m_bllCK_CourseTab = new TrainingDB.BLL.CK_CourseTab();
        private TrainingDB.BLL.CK_ClassRoomExTab m_bllCK_ClassRoomExTab = new TrainingDB.BLL.CK_ClassRoomExTab();
        private TrainingDB.BLL.CK_ClassTab m_bllCK_ClassTab = new TrainingDB.BLL.CK_ClassTab();
        private TrainingDB.BLL.CK_TimeSegTab m_bllCK_TimeSegTab = new TrainingDB.BLL.CK_TimeSegTab();
        private TrainingDB.BLL.CK_ClassWayTab m_bllCK_ClassWayTab = new TrainingDB.BLL.CK_ClassWayTab();
        private TrainingDB.BLL.CK_SchdDetail m_bllCK_SchdDetail = new TrainingDB.BLL.CK_SchdDetail();
 
        private int m_nDelIndex = -1;
        private bool m_bInsertFlag = false;
        private Dictionary<string, string> m_dicColName2AliasName = new Dictionary<string, string>();
        private Dictionary<string, string> m_dicColAliasName2Name = new Dictionary<string, string>();
        private List<int> m_lstValidWeek = new List<int>();

    
        public Frm_ClassPrdSchd()
        {
            InitializeComponent();
        }
        private string GetClassPrdSchdNo()
        {
            int nMaxID = m_bllCK_ClassPrdSchdTab.GetMaxId();
            string strTemp = string.Format("{0:d4}", nMaxID.ToString());
            string strRet = "PK-" + strTemp.PadLeft(4, '0');
            return strRet;

        }
        private void InitColumnWidth()
        {

            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns[m_dicColName2AliasName[strTemp]].Width = Frm_Main.m_nDfuColWidth;

            }
            ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["星期设置"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["缺省学时"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["教师课时费标准"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否排除节假日"].Width = 60;


        }
        private void ShowAllRecordInDataGridView(string strWhere)
        {
            ultraGrid1.DataSource = null;
            DataSet ds = m_bllCK_ClassPrdSchdTab.GetList(strWhere);
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ds.Tables[0].Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];
      
            }

            DataSet dsTemp = m_bllCK_SchoolTab.GetOnlyList("");

            this.ultraDropDownDep.DataSource = dsTemp.Tables[0];
            this.ultraDropDownDep.DisplayMember = "校区名称";
            this.ultraDropDownDep.ValueMember = "CK_SchoolTabID";
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownDep.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns["校区名称"].Hidden = false;

            

            dsTemp = m_bllCK_TeacherTab.GetOnlyList("");

            this.ultraDropDownT1.DataSource = dsTemp.Tables[0];
            this.ultraDropDownT1.DisplayMember = "教师名称";
            this.ultraDropDownT1.ValueMember = "CK_TeacherTabID";
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownT1.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns["教师名称"].Hidden = false;

            dsTemp = m_bllCK_ClassWayTab.GetList("");

            this.ultraDropDownClassWay.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClassWay.DisplayMember = "CK_ClassWayName";
            this.ultraDropDownClassWay.ValueMember = "CK_ClassWayTabID";
            this.ultraDropDownClassWay.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClassWay.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClassWay.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClassWay.DisplayLayout.Bands[0].Columns["CK_ClassWayName"].Hidden = false;

            dsTemp = m_bllCK_CourseTab.GetOnlyList("");

            this.ultraDropDownCourse.DataSource = dsTemp.Tables[0];
            this.ultraDropDownCourse.DisplayMember = "课程名称";
            this.ultraDropDownCourse.ValueMember = "CK_CourseTabID";
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns["课程名称"].Hidden = false;

            dsTemp = m_bllCK_ClassRoomExTab.GetList("");

            this.ultraDropDownClassRoom.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClassRoom.DisplayMember = "CK_ClassRoomExEx";
            this.ultraDropDownClassRoom.ValueMember = "CK_ClassRoomExTabID";
            this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns["CK_ClassRoomExEx"].Hidden = false;

            dsTemp = m_bllCK_ClassTab.GetList("");

            this.ultraDropDownClass.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClass.DisplayMember = "CK_className";
            this.ultraDropDownClass.ValueMember = "CK_ClassTabID";
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClass.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns["CK_className"].Hidden = false;

            dsTemp = m_bllCK_TimeSegTab.GetList("");

            this.ultraDropDownTimeSeg.DataSource = dsTemp.Tables[0];
            this.ultraDropDownTimeSeg.DisplayMember = "CK_ClassTime";
            this.ultraDropDownTimeSeg.ValueMember = "CK_TimeSegTabID";
            this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns["CK_ClassTime"].Hidden = false;
     
            ultraGrid1.DataSource = ds.Tables[0];
            ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["校区名称"].ValueList = this.ultraDropDownDep;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["讲师姓名"].ValueList = this.ultraDropDownT1;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["上课方式"].ValueList = this.ultraDropDownClassWay;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["课程名称"].ValueList = this.ultraDropDownCourse;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["班级名称"].ValueList = this.ultraDropDownClass;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["教室"].ValueList = this.ultraDropDownClassRoom;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].ValueList = this.ultraDropDownTimeSeg;
           
        }
        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridView("");
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();   
            InitColumnWidth();
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }
        private void AddNewRow()
        {
            if (Frm_Main.CheckPerm(this.Text, "增加"))
            {
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
            else
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
       
            if (e.KeyCode == Keys.Enter)
            {
                int nIndex = ultraGrid1.ActiveRow.Index;
                if (nIndex == -1)
                {
                    List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

                    string strColumnName;
                    string strColumnValue;
                    SearchCondition condition = new SearchCondition();
                    foreach (object o in lstO)
                    {
                        ColumnFilter cf = (ColumnFilter)o;
                        strColumnName = cf.Column.Key;
                        strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";
                        if (strColumnValue != "")
                        {
                            condition = condition.AddCondition(m_dicColAliasName2Name[strColumnName], strColumnValue, SqlOperator.Equal);
                        }
                    }

                    string filter = condition.BuildConditionSql();
                    filter = filter.Replace("Where", "");
                    ShowAllRecordInDataGridView(filter);
                }
            }
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    AddNewRow();
                    //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }

        }
          

    
         
        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTab = new TrainingDB.Model.CK_ClassPrdSchdTab();

                modelCK_ClassPrdSchdTab.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                modelCK_ClassPrdSchdTab.CK_OperUserID = Frm_Main.m_nLoginUserId;
                modelCK_ClassPrdSchdTab.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_ClassRoomExTabID = Convert.ToInt32(CurrentUGR.Cells["教室"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["班级名称"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_ClassWayTabID = Convert.ToInt32(CurrentUGR.Cells["上课方式"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_TimeSegTabID = Convert.ToInt32(CurrentUGR.Cells["时段"].Value.ToString());

                modelCK_ClassPrdSchdTab.week = CurrentUGR.Cells["星期设置"].Value.ToString();
                modelCK_ClassPrdSchdTab.dftHourQtty = Convert.ToDecimal(CurrentUGR.Cells["缺省学时"].Value.ToString());
                modelCK_ClassPrdSchdTab.noHoliday = Convert.ToBoolean(CurrentUGR.Cells["是否排除节假日"].Value.ToString());
                modelCK_ClassPrdSchdTab.prdSchdlMemo = CurrentUGR.Cells["备注"].Value.ToString();
                modelCK_ClassPrdSchdTab.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["教师课时费标准"].Value.ToString());
                modelCK_ClassPrdSchdTab.CK_ClassPrdSchdNo = GetClassPrdSchdNo();
                if (CurrentUGR.Cells["开始日期"].Value.ToString() == "")
                {
                    modelCK_ClassPrdSchdTab.beginDate = null;
                }
                else
                {
                    modelCK_ClassPrdSchdTab.beginDate = Convert.ToDateTime(CurrentUGR.Cells["开始日期"].Value.ToString());
                }
                if (CurrentUGR.Cells["结束日期"].Value.ToString() == "")
                {
                    modelCK_ClassPrdSchdTab.endDate = null;
                }
                else
                {
                    modelCK_ClassPrdSchdTab.endDate = Convert.ToDateTime(CurrentUGR.Cells["结束日期"].Value.ToString());
                }

                int nId = m_bllCK_ClassPrdSchdTab.Add(modelCK_ClassPrdSchdTab);

                ShowAllRecordInDataGridView("");
                MessageBox.Show("添加记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private void InitNewAddRowValue(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["校区名称"].Value = 1;
            CurrentUGR.Cells["录入人"].Value = Frm_Main.m_nLoginUserId;
            CurrentUGR.Cells["讲师姓名"].Value = m_bllCK_TeacherTab.GetMaxId() - 1; 
            CurrentUGR.Cells["课程名称"].Value = 1;

            CurrentUGR.Cells["教室"].Value = m_bllCK_ClassRoomExTab.GetMaxId() - 1; ;
            CurrentUGR.Cells["班级名称"].Value = m_bllCK_ClassTab.GetMaxId() - 1; 
            CurrentUGR.Cells["时段"].Value = 1;
            CurrentUGR.Cells["上课方式"].Value = 1;
            CurrentUGR.Cells["星期设置"].Value = "";
            CurrentUGR.Cells["缺省学时"].Value = 0;
            CurrentUGR.Cells["是否排除节假日"].Value = false;

            CurrentUGR.Cells["备注"].Value = "";
            CurrentUGR.Cells["教师课时费标准"].Value = 0;
         
     

            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[0].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }

        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
            
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }

        private List<DateTime> GetDateTimeLst(DateTime dtStart, DateTime dtEnd, List<int> lstWeeks)
        {
             List<DateTime> lstAllDays = new List<DateTime>();

             for (DateTime dt = dtStart; dt <= dtEnd; dt = dt.AddDays(1))
             {
                 DayOfWeek dow = dt.DayOfWeek;
                 if (lstWeeks.Contains((int)dow))
                     lstAllDays.Add(dt);
             }

             return lstAllDays;
        }

        private void ArrangeClass(TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTab, List<int> lstTemp)
        {
            Hashtable SQLStringList = new Hashtable();
            ArrayList arrayList = new ArrayList();
            int nIndex = 0;
            TrainingDB.Model.CK_TimeSegTab modelCK_TimeSegTab = m_bllCK_TimeSegTab.GetModel(modelCK_ClassPrdSchdTab.CK_TimeSegTabID);
            TrainingDB.Model.CK_ClassTab modelCK_ClassTab = m_bllCK_ClassTab.GetModel(modelCK_ClassPrdSchdTab.CK_ClassTabID);
            for (DateTime dt = (DateTime)modelCK_ClassPrdSchdTab.beginDate; dt <= (DateTime)modelCK_ClassPrdSchdTab.endDate; dt = dt.AddDays(1))
            {
                DayOfWeek dow = dt.DayOfWeek;
                if (lstTemp.Contains((int)dow))
                {
                    TrainingDB.Model.CK_SchdDetail modelCK_SchdDetail = new TrainingDB.Model.CK_SchdDetail();
                    modelCK_SchdDetail.CK_ClassPrdSchdTabID = modelCK_ClassPrdSchdTab.CK_ClassPrdSchdTabId;
                    modelCK_SchdDetail.CK_ClassRoomExTabID = modelCK_ClassPrdSchdTab.CK_ClassRoomExTabID;
                    modelCK_SchdDetail.CK_ClassTabID = modelCK_ClassPrdSchdTab.CK_ClassTabID;
                    modelCK_SchdDetail.CK_CourseTabID = modelCK_ClassPrdSchdTab.CK_CourseTabID;
                    modelCK_SchdDetail.CK_SchoolTabID = modelCK_ClassPrdSchdTab.CK_SchoolTabID;
                    modelCK_SchdDetail.CK_TeacherTabID = modelCK_ClassPrdSchdTab.CK_TeacherTabID;
                    modelCK_SchdDetail.CK_TimeSegTabID = modelCK_ClassPrdSchdTab.CK_TimeSegTabID;
                    modelCK_SchdDetail.classDate = dt;
                    modelCK_SchdDetail.hourFee = modelCK_ClassTab.chargeStd;
                    modelCK_SchdDetail.hourFeeStd = modelCK_ClassTab.hourFeeStd;
                    modelCK_SchdDetail.hourQtty = (decimal)modelCK_TimeSegTab.CK_DftHourQtty;
                    modelCK_SchdDetail.isStudy = false;
                    m_bllCK_SchdDetail.TransAdd(modelCK_SchdDetail, SQLStringList, arrayList, nIndex);
                    nIndex++;

                }
            }
            if(nIndex > 0)
                m_bllCK_SchdDetail.ExecuteSqlTran(SQLStringList, arrayList);
            return;
        }

        private bool ConflictCheck(TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTab, List<DateTime> lstTempDateTime)
        {
            bool bRet = false;
            DataSet ds = m_bllCK_SchdDetail.GetList("CK_SchdDetail.classDate >= '" + modelCK_ClassPrdSchdTab.beginDate + "'" 
                +" and CK_SchdDetail.classDate <= '" + modelCK_ClassPrdSchdTab.endDate + "'" 
                +  " and CK_SchdDetail.CK_TeacherTabID = '" + modelCK_ClassPrdSchdTab.CK_TeacherTabID + "'"
                + " and CK_SchdDetail.CK_TimeSegTabID = '" + modelCK_ClassPrdSchdTab.CK_TimeSegTabID + "'");

           
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime dtTemp = (DateTime)ds.Tables[0].Rows[i]["classDate"];
                    if (lstTempDateTime.Contains(dtTemp))
                    {
                        MessageBox.Show("与" + dtTemp.ToShortDateString() + "日排课明细的教师冲突！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return true;
                    }
                }

            }

            ds = m_bllCK_SchdDetail.GetList("CK_SchdDetail.classDate >= '" + modelCK_ClassPrdSchdTab.beginDate + "'"
                + " and CK_SchdDetail.classDate <= '" + modelCK_ClassPrdSchdTab.endDate + "'"
                + " and CK_SchdDetail.CK_ClassRoomExTabID = '" + modelCK_ClassPrdSchdTab.CK_ClassRoomExTabID + "'"
                + " and CK_SchdDetail.CK_TimeSegTabID = '" + modelCK_ClassPrdSchdTab.CK_TimeSegTabID + "'");


            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime dtTemp = (DateTime)ds.Tables[0].Rows[i]["classDate"];
                    if (lstTempDateTime.Contains(dtTemp))
                    {
                        MessageBox.Show("与" + dtTemp.ToShortDateString() + "日排课明细的教室冲突！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return true;
                    }
                }

            }

            ds = m_bllCK_SchdDetail.GetList("CK_SchdDetail.classDate >= '" + modelCK_ClassPrdSchdTab.beginDate + "'"
             + " and CK_SchdDetail.classDate <= '" + modelCK_ClassPrdSchdTab.endDate + "'"
             + " and CK_SchdDetail.CK_ClassTabID = '" + modelCK_ClassPrdSchdTab.CK_ClassTabID + "'"
             + " and CK_SchdDetail.CK_TimeSegTabID = '" + modelCK_ClassPrdSchdTab.CK_TimeSegTabID + "'");


            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime dtTemp = (DateTime)ds.Tables[0].Rows[i]["classDate"];
                    if (lstTempDateTime.Contains(dtTemp))
                    {
                        MessageBox.Show("与" + dtTemp.ToShortDateString() + "日排课明细的班级冲突！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return true;
                    }
                }

            }

            return bRet;
        }

        private bool CompareCK_ClassPrdSchdTabObject(TrainingDB.Model.CK_ClassPrdSchdTab a
            , TrainingDB.Model.CK_ClassPrdSchdTab b)
        {
            bool bRet = false;
            bRet = (a.week == b.week
                && a.CK_TeacherTabID == b.CK_TeacherTabID
                && a.CK_CourseTabID == b.CK_CourseTabID
                && a.CK_ClassRoomExTabID == b.CK_ClassRoomExTabID
                && a.CK_ClassTabID == b.CK_ClassTabID
                && a.CK_TimeSegTabID == b.CK_TimeSegTabID
                && a.CK_ClassWayTabID == b.CK_ClassWayTabID
                && a.beginDate == b.beginDate
                && a.endDate == b.endDate
                && a.noHoliday == b.noHoliday);
            return bRet;
        }

        private bool ModifyGoodsDetail(int nRowIndex)
        {

            try
            {

                if (!Frm_Main.CheckPerm(this.Text, "修改"))
                {
                    MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                List<int> lstTemp = new List<int>();
              
                char[] cWeek = CurrentUGR.Cells["星期设置"].Value.ToString().ToCharArray();
                foreach (char c in cWeek)
                {
                    int nTemp = Char2Num(c);
                    if (!m_lstValidWeek.Contains(nTemp))
                        continue;
                    else
                    {
                        if (!lstTemp.Contains(nTemp))
                            lstTemp.Add(nTemp);
                    }

                }

                lstTemp.Sort();
                string strTrueWeek = "";

                foreach (int n in lstTemp)
                {
                    char cTemp = Num2Upper(n.ToString().ToCharArray()[0]);
                    if (strTrueWeek == "")
                        strTrueWeek = cTemp.ToString();
                    else if (!strTrueWeek.Contains(cTemp))
                        strTrueWeek += "," + cTemp.ToString();
                }

  
                //ArrangeClass(DateTime.Now.Date, DateTime.Now.Date.AddDays(30), lstTemp);

                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTab = m_bllCK_ClassPrdSchdTab.GetModel(nSelectFinRecvMoneyDetailTab_NewID);
                TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTabOld = m_bllCK_ClassPrdSchdTab.GetModel(nSelectFinRecvMoneyDetailTab_NewID);
              
                if (CurrentUGR.Cells["开始日期"].Value.ToString() == "")
                {
                    modelCK_ClassPrdSchdTab.beginDate = null;
                }
                else
                {
                    modelCK_ClassPrdSchdTab.beginDate = Convert.ToDateTime(CurrentUGR.Cells["开始日期"].Value.ToString());
                }
                if (CurrentUGR.Cells["结束日期"].Value.ToString() == "")
                {
                    modelCK_ClassPrdSchdTab.endDate = null;
                }
                else
                {
                    modelCK_ClassPrdSchdTab.endDate = Convert.ToDateTime(CurrentUGR.Cells["结束日期"].Value.ToString());
                }

                if (modelCK_ClassPrdSchdTab.beginDate == null || modelCK_ClassPrdSchdTab.endDate == null)
                {
                    MessageBox.Show("必须设置开始日期和结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }

                modelCK_ClassPrdSchdTab.week = strTrueWeek;
                CurrentUGR.Cells["星期设置"].Value = strTrueWeek;
                modelCK_ClassPrdSchdTab.noHoliday = Convert.ToBoolean(CurrentUGR.Cells["是否排除节假日"].Value.ToString());



                string strBGH = CurrentUGR.Cells["校区名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_SchoolTab.GetList("CK_SchoolTabName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_SchoolTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_SchoolTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["讲师姓名"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TeacherTab.GetList("CK_TeacherName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_TeacherTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TeacherTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["教室"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_ClassRoomExTabID = Convert.ToInt32(CurrentUGR.Cells["教室"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassRoomExTab.GetList("CK_ClassRoomExEx = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_ClassRoomExTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassRoomExTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["课程名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_CourseTab.GetList("CK_course = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_CourseTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_CourseTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["班级名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["班级名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassTab.GetList("CK_className = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_ClassTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["上课方式"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_ClassWayTabID = Convert.ToInt32(CurrentUGR.Cells["上课方式"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassWayTab.GetList("CK_ClassWayName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_ClassWayTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassWayTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["时段"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassPrdSchdTab.CK_TimeSegTabID = Convert.ToInt32(CurrentUGR.Cells["时段"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TimeSegTab.GetList("CK_ClassTime = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassPrdSchdTab.CK_TimeSegTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TimeSegTabID"].ToString(), 10);
                    }
                }


                if (CompareCK_ClassPrdSchdTabObject(modelCK_ClassPrdSchdTabOld, modelCK_ClassPrdSchdTab))
                {

                    modelCK_ClassPrdSchdTab.dftHourQtty = Convert.ToDecimal(CurrentUGR.Cells["缺省学时"].Value.ToString());
                    modelCK_ClassPrdSchdTab.prdSchdlMemo = CurrentUGR.Cells["备注"].Value.ToString();
                    modelCK_ClassPrdSchdTab.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["教师课时费标准"].Value.ToString());
                    m_bllCK_ClassPrdSchdTab.Update(modelCK_ClassPrdSchdTab);
                }
                else
                {

                    List<DateTime> lstTempDateTime = GetDateTimeLst((DateTime)modelCK_ClassPrdSchdTab.beginDate
                    , (DateTime)modelCK_ClassPrdSchdTab.endDate, lstTemp);
                    bool bConflict = ConflictCheck(modelCK_ClassPrdSchdTab, lstTempDateTime);
                    if (!bConflict)
                    {
                        m_bllCK_ClassPrdSchdTab.Update(modelCK_ClassPrdSchdTab);
                        ArrangeClass(modelCK_ClassPrdSchdTab, lstTemp);
                    }
                }

              //  MessageBox.Show("修改教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;



                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_ClassPrdSchdTab modelCK_ClassPrdSchdTabOld = m_bllCK_ClassPrdSchdTab.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                if (modelCK_ClassPrdSchdTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCK_ClassPrdSchdTab.Delete(nSelectFinRecvMoneyDetailTab_NewID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void 增加一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                AddNewRow();
                //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void 删除一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Frm_Main.CheckPerm(this.Text, "删除"))
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid1.ActiveRow != null)
                {

                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private int Char2Num(char cNum)
        {
            int nRet = 0;
            switch (cNum)
            {
                case '1':
                case '一':
                    {
                        nRet = 1;
                        break;
                    }
                case '2':
                case '二':
                    {
                        nRet = 2;
                        break;
                    }
                case '3':
                case '三':
                    {
                        nRet = 3;
                        break;
                    }
                case '4':
                case '四':
                    {
                        nRet = 4;
                        break;
                    }
                case '5':
                case '五':
                    {
                        nRet = 5;
                        break;
                    }
                case '6':
                case '六':
                    {
                        nRet = 6;
                        break;
                    }
                case '7':
                case '七':
                case '日':
                    {
                        nRet = 7;
                        break;
                    }
                default:
                    break;
            }

            return nRet;
        }

        private char Num2Upper(char cNum)
        {
            char cRet = new char();
            switch(cNum)
            {
                case '1':
                case '一':
                    {
                        cRet = '一';
                        break;
                    }
                case '2':
                case '二':
                    {
                        cRet = '二';
                        break;
                    }
                case '3':
                case '三':
                    {
                        cRet = '三';
                        break;
                    }
                case '4':
                case '四':
                    {
                        cRet = '四';
                        break;
                    }
                case '5':
                case '五':
                    {
                        cRet = '五';
                        break;
                    }
                case '6':
                case '六':
                    {
                        cRet = '六';
                        break;
                    }
                case '7':
                case '七':
                case '日':
                    {
                        cRet = '日';
                        break;
                    }
                default:
                    break;
            }

            return cRet;
        }


        private void Frm_ClassRoom_Load_1(object sender, EventArgs e)
        {
            //List<int> lstTemp = new List<int>();
            //lstTemp.Add(0);
            //lstTemp.Add(3);
      
            //ArrangeClass(DateTime.Now.Date, DateTime.Now.Date.AddDays(30), lstTemp);
            m_lstValidWeek.Add(1);
            m_lstValidWeek.Add(2);
            m_lstValidWeek.Add(3);
            m_lstValidWeek.Add(4);
            m_lstValidWeek.Add(5);
            m_lstValidWeek.Add(6);
            m_lstValidWeek.Add(7);
            //m_lstValidWeek.Add('一');
            //m_lstValidWeek.Add('二');
            //m_lstValidWeek.Add('三');
            //m_lstValidWeek.Add('四');
            //m_lstValidWeek.Add('五');
            //m_lstValidWeek.Add('六');
            //m_lstValidWeek.Add('日');
            //DateTime dt = DateTime.Now.Date;
            //DateTime dt2 = dt.AddDays(1);
            //DayOfWeek d = dt.DayOfWeek;
            m_dicColName2AliasName.Add("CK_SchoolTabName", "校区名称");
            m_dicColName2AliasName.Add("Name", "录入人");
            m_dicColName2AliasName.Add("CK_TeacherName", "讲师姓名");
      
            m_dicColName2AliasName.Add("CK_course", "课程名称");
            
            m_dicColName2AliasName.Add("CK_ClassRoomExEx", "教室");
            m_dicColName2AliasName.Add("CK_className", "班级名称");
            m_dicColName2AliasName.Add("CK_ClassTime", "时段");

            m_dicColName2AliasName.Add("beginDate", "开始日期");
            m_dicColName2AliasName.Add("endDate", "结束日期");
            m_dicColName2AliasName.Add("CK_ClassWayName", "上课方式");
            m_dicColName2AliasName.Add("week", "星期设置");


            m_dicColName2AliasName.Add("CK_ClassPrdSchdNo", "排课编号");
            m_dicColName2AliasName.Add("dftHourQtty", "缺省学时");
            m_dicColName2AliasName.Add("prdSchdlMemo", "备注");
            m_dicColName2AliasName.Add("hourFeeStd", "教师课时费标准");
            m_dicColName2AliasName.Add("noHoliday", "是否排除节假日");


            this.toolTipManager.AutoPopDelay = 100000;
            m_dicHelper.Add("星期设置"
, @"提示：上课方式为每周或隔周时，
“星期”为必须填。其正确填写格式为
“一，二，三...，日”也可填“123...7”。
例如，周五，六，日，您只需填“567”即可");

            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                //ds.Tables[0].Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];
                m_dicColAliasName2Name.Add(m_dicColName2AliasName[strTemp], strTemp);
            }
        }

        private void buttonExportExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void ultraGrid1_MouseEnterElement(object sender, Infragistics.Win.UIElementEventArgs e)
        {
              UltraGridCell enteredCell = e.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell;
              //enteredCell.Column.Header.Caption;

              if (enteredCell != null)
              {
                  string strTemp = "";
                  if (m_dicHelper.Keys.Contains(enteredCell.Column.Header.Caption))
                  {
                      strTemp = m_dicHelper[enteredCell.Column.Header.Caption];
                  }
                  else
                  {
                      strTemp = enteredCell.Text;
                  }
                  if (enteredCell.Column.DataType == typeof(bool))
                  {
                      return;
                  }

                  UltraToolTipInfo gridToolTip = new UltraToolTipInfo(strTemp, ToolTipImage.Default, null, DefaultableBoolean.Default);
                  this.toolTipManager.SetUltraToolTip(this, gridToolTip);
                  this.toolTipManager.ShowToolTip(this);

                  return;
              }

              Infragistics.Win.UltraWinGrid.ColumnHeader enteredHeader
                  = e.Element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) 
                  as Infragistics.Win.UltraWinGrid.ColumnHeader;
              if (enteredHeader != null)
              {
                  enteredHeader.ToolTipText = string.Empty;
                  UltraToolTipInfo gridToolTip = new UltraToolTipInfo(enteredHeader.Caption, ToolTipImage.Default, null, DefaultableBoolean.Default);
                  this.toolTipManager.SetUltraToolTip(this, gridToolTip);
                  this.toolTipManager.ShowToolTip(this);
              }
        }

        private void ultraGrid1_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e)
        {
    
             UltraGridCell enteredCell = e.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell;
             Infragistics.Win.UltraWinGrid.ColumnHeader enteredHeader
                 = e.Element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as
                 Infragistics.Win.UltraWinGrid.ColumnHeader;
             if (null != enteredCell || null != enteredHeader)
             {
                 this.toolTipManager.HideToolTip();
             }
        }

        private void ultraGrid1_Paint(object sender, PaintEventArgs e)
        {
             base.OnPaint(e);
             this.ultraGrid1.DisplayLayout.Override.TipStyleCell = TipStyle.Hide;
             this.ultraGrid1.DisplayLayout.Override.TipStyleHeader = TipStyle.Hide;
        }

        private void ultraGridExcelExporter1_CellExported(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.CellExportedEventArgs e)
        {

        }

       


    }
}



